package com.fengwk.user.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.fengwk.support.util.ResultUtils;
import com.fengwk.user.face.annotation.Permission;
import com.fengwk.user.face.model.Channel;
import com.fengwk.user.service.ChannelService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

@Permission("channel")
@Api(tags = "通道")
@RestController
@RequestMapping("/api/channel")
public class ChannelController {

	@Autowired
	private HttpServletRequest request;
	@Autowired
	private HttpServletResponse response;
	
	@Autowired
	private ChannelService channelService;
	
	@ApiOperation(
			value = "存储通道", 
			response = Channel.class)
	@PostMapping("/saveChannel")
	public void saveChannel(
			@ApiParam(value = "通道", required = true) @RequestParam(value = "channelName", required = true) String channel,
			@ApiParam(value = "策略", required = true) @RequestParam(value = "strategy", required = true) Integer strategy,
			@ApiParam(value = "描述", required = false) @RequestParam(value = "description", required = false) String description) {
		ResultUtils.returnJsonResult(request, response, channelService.saveChannel(
				channel, strategy, description));
	}
	
	@ApiOperation(
			value = "移除通道", 
			response = Channel.class)
	@PostMapping("/removeChannel")
	public void removeChannel(
			@ApiParam(value = "通道", required = true) @RequestParam(value = "channelName", required = true) String channel) {
		ResultUtils.returnJsonResult(request, response, channelService.removeChannel(channel));
	}
	
	@ApiOperation(
			value = "获取通道列表", 
			response = Channel.class)
	@PostMapping("/listChannel")
	public void listChannel() {
		ResultUtils.returnJsonResult(request, response, channelService.listChannel());
	}

}
